﻿using System;
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;

using ComLib.Queue;
using ComLib.Web.Modules.Resources;
using ComLib.Web.Modules.OptionDefs;
using ComLib.Web.Modules.Widgets;
using ComLib.MapperSupport;
using ComLib.Scheduling.Tasks;


namespace ComLib.CMS.Models.Tasks
{

    /// <summary>
    /// Reloads the resources.
    /// </summary>
    [Task(Name = "ResourceReload", DisplayName = "Resource Reload", Description = "Reloads all the resource strings into the database", IsOnDemand = true, SortIndex = 5)]
    public class ResourceReload : ITask
    {
        /// <summary>
        /// Process the tags.
        /// </summary>
        public void Process()
        {
            var server = HttpContext.Current.Server;
            Resource.DeleteAll();
            OptionDef.DeleteAll();
            //Widget.DeleteAll();
            Resource.Create(Mapper.MapConfigFile<Resource>(server.MapPath("~/config/data/resources.csv.config")), r => r.Language, r => r.ResourceType, r => r.Section, r => r.Key);
            OptionDef.Create(Mapper.MapConfigFile<OptionDef>(server.MapPath("~/config/data/optiondefs.csv.config")), o => o.Section, o => o.Key);
            //Widget.Create(Mapper.MapConfigFile<Widget>(server.MapPath("~/config/data/widgetdefs.csv.config")), w => w.Name);
        }
    }
}
